package com.tea.tl.service.impl;

import com.tea.common.dto.DiscountCouponAddDto;
import com.tea.common.vo.R;
import com.tea.tl.dao.DiscountCouponDao;
import com.tea.tl.domain.DiscountCoupon;
import com.tea.tl.service.intf.DiscountCouponService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class DiscountCouponServiceImpl implements DiscountCouponService {
    @Resource
    private DiscountCouponDao dao;
    /**
     * 1.新增优惠券*/
    @Override
    public R add(DiscountCouponAddDto dto) {
        if (dto!=null){
            DiscountCoupon discountCoupon = new DiscountCoupon();
            BeanUtils.copyProperties(dto,discountCoupon);
            discountCoupon.setCtime(new Date());
            if (dao.insert(discountCoupon)>0){
                return R.ok();
            }
        }
        return R.fail();
    }
    /**
     * 2.查询全部*/
    @Override
    public R select() {
        return R.ok(dao.selectList(null));
    }
}
